package com.gibs.peixunapi.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import com.gibs.peixunapi.model.ExerciseRecord;

@Repository
public interface ExerciseRecordDao extends JpaRepository<ExerciseRecord, Integer>, JpaSpecificationExecutor<ExerciseRecord> {

	@Query("from ExerciseRecord where answer = ?1")
	List<ExerciseRecord> find(String name);

	@Query("from ExerciseRecord where answer like ?1")
	List<ExerciseRecord> findLike(String name);

	@Query(value = "select * from ExerciseRecord limit ?, ?", nativeQuery = true)
	List<ExerciseRecord> findPage(Integer offset, Integer size);

	@Query(value = "select * from ExerciseRecord where answer = ? limit ?, ?", nativeQuery = true)
	List<ExerciseRecord> findPage(String name, Integer offset, Integer size);

	@Query(value = "select * from ExerciseRecord where answer like ? limit ?, ?", nativeQuery = true)
	List<ExerciseRecord> findPageLike(String name, Integer offset, Integer size);

	@Query(value = "select count(*) from ExerciseRecord where answer = ?", nativeQuery = true)
	Long count(String name);

	@Query(value = "select count(*) from ExerciseRecord where answer like ?", nativeQuery = true)
	Long countLike(String name);
	
	@Query("from ExerciseRecord order by id asc")
	List<ExerciseRecord> findAllAsc();

	Integer countExerciseRecordsByStudent_IdAndExercise_Id(Integer studentId, Integer exerciseId);


}

